//
//  ViewController.swift
//  光波扫描动画效果
//
//  Created by app on 2017/4/17.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 设置扫描背景
        let image = UIImage(named: "unLock.jpg")
        let imageView = UIImageView(image: image)
        imageView.contentMode = .scaleAspectFit
        imageView.frame  = view.bounds
        imageView.center = view.center
        view.backgroundColor = .black
        view.addSubview(imageView)
        // 设置图层
        let gradienLayer =  CAGradientLayer()
        gradienLayer.frame = CGRect(x: 105, y: 330, width: 200, height: 200)
        imageView.layer.addSublayer(gradienLayer)
        gradienLayer.startPoint = CGPoint(x: 0, y: 0)
        gradienLayer.endPoint = CGPoint(x: 0, y: 1)
        gradienLayer.colors = [UIColor.clear.cgColor,UIColor.white.cgColor,UIColor.clear]
        gradienLayer.locations = [0.0,0.1,0.2]
        // 设置CABasiciton
        let animation = CABasicAnimation()
        animation.keyPath = "locations"
        animation.fromValue = [0.0,0.1,0.2]
        animation.toValue = [0.8,0.9,1.0]
        animation.duration = 3.0
        animation.repeatCount = 10
        gradienLayer.add(animation, forKey: nil)
        
//        let gradientAnimation:CABasicAnimation = CABasicAnimation()
//        gradientAnimation.keyPath = "locations"
//        gradientAnimation.fromValue = [0.0,0.1,0.2];
//        gradientAnimation.toValue = [0.8,0.9,1.0];
//        gradientAnimation.duration = 3.0;
//        gradientAnimation.repeatCount = 10;
//        gradientLayer.add(gradientAnimation, forKey: nil)
        
    }
}

